package com.qige.homework;

public class homework2 {
    public static void main(String[] args) {
        Worker worker1 = new Worker();
        Worker worker2 = new Worker();
        apple a1 = new apple(5,"青色");
        apple a2 = new apple(3,"红色");
        worker1.pickApple(new CompareAble() {
            @Override
            public void compare(apple a, apple b) {
                CompareAble.super.compare(a, b);
            }
        }, a1, a2);
        worker2.pickApple(new CompareAble() {
            @Override
            public void compare(apple a, apple b) {
                System.out.println("挑红的:");
                if ("红色".equals(a.getColor())){
                    System.out.println(a.getSize() + "-" + a.getColor());
                }else if ("红色".equals(b.getColor())){
                    System.out.println(b.getSize() + "-" + b.getColor());
                }
            }
        },a1,a2);
    }
}
class apple{
    public double size;
    public String color;

    public apple() {
    }

    public apple(double size, String color) {
        this.size = size;
        this.color = color;
    }

    public double getSize() {
        return size;
    }

    public void setSize(double size) {
        this.size = size;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }
}
interface CompareAble{
    default void compare(apple a, apple b){
        System.out.println("默认挑大的:");
        if (a.getSize() > b.getSize()){
            System.out.println(a.getSize() + "-" + a.getColor());
        } else {
            System.out.println(b.getSize() + "-" + b.getColor());
        }

    }
}
class Worker{
    public void pickApple(CompareAble c,apple a1,apple a2){
        c.compare(a2,a1);
    }
}